package com.dms.modules.community.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dms.modules.community.entity.CommunitySearchHistory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommunitySearchHistoryMapper extends BaseMapper<CommunitySearchHistory> {
    
    /**
     * 获取热门搜索词
     */
    @Select("SELECT keyword, SUM(search_count) as search_count FROM community_search_history " +
            "WHERE deleted = 0 GROUP BY keyword ORDER BY search_count DESC LIMIT #{limit}")
    List<CommunitySearchHistory> getHotKeywords(Integer limit);
    
    /**
     * 获取用户最近搜索历史
     */
    @Select("SELECT * FROM community_search_history WHERE user_id = #{userId} AND deleted = 0 " +
            "ORDER BY last_search_time DESC LIMIT #{limit}")
    List<CommunitySearchHistory> getUserRecentSearches(Long userId, Integer limit);
} 